﻿
using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.deepprocessing
{
    public class DeepprocessingBossHandler : IRequestHandler<DeepprocessingBossCommond, Rulst>
    {

        private readonly IbaseRpository<ProcessMess> _ProcessMess;

        public DeepprocessingBossHandler(IbaseRpository<ProcessMess> processMess)
        {
            _ProcessMess = processMess;
        }
        public async Task<Rulst> Handle(DeepprocessingBossCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };
            var list=_ProcessMess.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid).FirstOrDefault();

            if (list != null) {


                list.Processlicence = request.Processlicence;
                    list.ProcessBossName = request.ProcessBossName;

                _ProcessMess.update(list);
                query.Code = 1;
                query.MSG = "修改成功";
            }
            else
            {

                var query1 = new ProcessMess()
                {

                    Processlicence = request.Processlicence,
                    ProcessBossName = request.ProcessBossName,
                      ProDuctionBasicid = request.ProDuctionBasicid,
                      Processclass="",
                      Processid=0,
                      ProcessLot="",
                      ProcessPersonincharge="",

                };
                _ProcessMess.Add(query1);
                query.Code = 1;
                query.MSG = "添加成功";
            }


            return query;
        }
    }
}
